#include "AudioHolder.h"
#include "GameState.h"
#include <string.h>

std::vector<ALLEGRO_SAMPLE *> AudioHolder::samples;
ALLEGRO_SAMPLE_ID* AudioHolder::sample_id;

AudioHolder::AudioHolder(void) {}

AudioHolder::~AudioHolder(void) {
	for(int i=0; i<samples.size(); ++i)
		al_destroy_sample(samples[i]);
}

bool AudioHolder::Initialize(void) {
	samples.push_back(al_load_sample("audio/IntroTheme.ogg"));
	samples.push_back(al_load_sample("audio/StageTheme.ogg"));
	samples.push_back(al_load_sample("audio/SpinachTheme.ogg"));
	samples.push_back(al_load_sample("audio/Danger.ogg"));
	samples.push_back(al_load_sample("audio/Death.ogg"));
	samples.push_back(al_load_sample("audio/StageClear.ogg"));
	return true;
}

void AudioHolder::ChangeToSound(const char *mode) {
	if(strcmp(mode, "level01") == 0) {
		al_stop_samples();
		al_play_sample(samples[1], 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, sample_id);
	}
	else if(strcmp(mode, "intro") == 0) {
		al_stop_samples();
		al_play_sample(samples[0], 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, sample_id);
	}
	else if(strcmp(mode, "spinach") == 0) {
		al_stop_samples();
		al_play_sample(samples[2], 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, sample_id);
	}
	else if(strcmp(mode, "danger") == 0) {
		al_stop_samples();
		al_play_sample(samples[3], 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, sample_id);
	}
	else if(strcmp(mode, "death") == 0) {
		al_stop_samples();
		al_play_sample(samples[4], 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, sample_id);
	}
	else if(strcmp(mode, "clear") == 0) {
		al_stop_samples();
		al_play_sample(samples[5], 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, sample_id);
	}
}
